home *** CD-ROM | disk | FTP | other *** search
-
-
-
- RRRRWWWWBBBBeeeennnncccchhhh((((3333CCCC++++++++)))) RRRRWWWWBBBBeeeennnncccchhhh((((3333CCCC++++++++))))
-
-
-
- NNNNaaaammmmeeee
- RWBench - Rogue Wave library class
-
- SSSSyyyynnnnooooppppssssiiiissss
- #include <rw/bench.h>
-
-
-
- ((((AAAAbbbbssssttttrrrraaaacccctttt bbbbaaaasssseeee ccccllllaaaassssssss))))
-
-
-
-
- DDDDeeeessssccccrrrriiiippppttttiiiioooonnnn
- This is an abstract class that can automate the process of benchmarking a
- piece of code. To use it, derive a class from RRRRWWWWBBBBeeeennnncccchhhh, including a
- definition for the virtual function ddddooooLLLLoooooooopppp((((uuuunnnnssssiiiiggggnnnneeeedddd lllloooonnnngggg NNNN)))).... This
- function should perform NNNN operations of the type that you are trying to
- benchmark. RRRRWWWWBBBBeeeennnncccchhhh will call ddddooooLLLLoooooooopppp(((()))) over and over again until a preset
- amount of time has elapsed. It will then sum the total number of
- operations performed. To run, construct an instance of your derived
- class and then call ggggoooo(((()))). Then call rrrreeeeppppoooorrrrtttt(((()))) to get a standard summary.
- For many compilers, this summary will automatically include the compiler
- type and memory model. You can call ooooppppssss(((()))),,,, oooouuuutttteeeerrrrLLLLooooooooppppssss(((()))),,,, eeeettttcccc. for more
- detail. If you wish to correct for overhead, then provide an iiiiddddlllleeeeLLLLoooooooopppp(((())))
- function which should do all non-benchmark-related calculations.
-
- PPPPeeeerrrrssssiiiisssstttteeeennnncccceeee
- None
-
- EEEExxxxaaaammmmpppplllleeee
- This example benchmarks the time required to return a hash value for a
- Rogue Wave string versus a Borland string.
-
- #include <rw/bench.h> /* Benchmark software */
-
-
-
- #include <rw/cstring.h> /* Rogue Wave string class */
- #include <stdlib.h>
- #include <iostream.h>
- #include <rw/ctoken.h>
- #include <rw/regexp.h>
- // The string to be hashed:
- const char* cs = "A multi-character string with lots of words in it to be parsed out and searched for.";
- class TestBrute : public RWBench {
- public:
- TestBrute() { }
- virtual void doLoop(unsigned long n);
- virtual void idleLoop(unsigned long n);
- virtual void what(ostream& s) const
- { s << "Brute force string search: 0; }
-
-
-
- PPPPaaaaggggeeee 1111
-
-
-
-
-
-
- RRRRWWWWBBBBeeeennnncccchhhh((((3333CCCC++++++++)))) RRRRWWWWBBBBeeeennnncccchhhh((((3333CCCC++++++++))))
-
-
-
- };
- class TestRW : public RWBench {
- public:
- TestRW() { }
- virtual void doLoop(unsigned long n);
- virtual void idleLoop(unsigned long n);
- virtual void what(ostream& s) const
- { s << "Rogue Wave search: 0; }
- };
- main(int argc, char* argv[]){
- cout << "Testing string
- // Test brute force string search algorithm:
- TestBrute other;
- other.parse(argc, argv);
- other.go();
- other.report(cout);
- // Test RW searching w/regular expressions:
- TestRW rw;
- rw.parse(argc, argv);
- rw.go();
- rw.report(cout);
- return 0;
- }
- void TestBrute::doLoop(unsigned long n){
- RWCString string(cs);
- RWCTokenizer *tokener;
- RWCString token;
- tokener = new RWCTokenizer(string);
- while(n--){
-
- if((token = (*tokener)()).isNull())
- {
- delete tokener;
- tokener = new RWCTokenizer(string);
- token = (*tokener)();
- }
- size_t j = 0;
- for(size_t i = 0; i < string.length() && j != token.length();
- i++)
- {
- j = 0;
- while((j < token.length()) && (string[i+j]==token[j]))
- j++;
- }
- }
- delete tokener;
- }
- void TestRW::doLoop(unsigned long n){
- RWCString string(cs);
- RWCTokenizer *tokener;
- RWCString token, result;
- RWCRegexp re("");
-
-
-
- PPPPaaaaggggeeee 2222
-
-
-
-
-
-
- RRRRWWWWBBBBeeeennnncccchhhh((((3333CCCC++++++++)))) RRRRWWWWBBBBeeeennnncccchhhh((((3333CCCC++++++++))))
-
-
-
- tokener = new RWCTokenizer(string);
-
-
-
-
- while(n--){
-
-
-
-
- if((token = (*tokener)()).isNull())
- {
- delete tokener;
- tokener = new RWCTokenizer(string);
- token = (*tokener)();
- }
-
-
-
- re = RWCRegexp(token);
-
-
-
- result = string(re); //Do the search!
-
-
-
- }
-
-
-
- delete tokener;
- }
-
-
-
- void TestBrute::idleLoop(unsigned long n){
-
-
-
- RWCString string(cs); // Subtract out the overhead
- RWCTokenizer *tokener;
- RWCString token;
- tokener = new RWCTokenizer(string);
-
- while(n--){
-
- if((token = (*tokener)()).isNull())
- {
- delete tokener;
- tokener = new RWCTokenizer(string);
- token = (*tokener)();
-
-
-
- PPPPaaaaggggeeee 3333
-
-
-
-
-
-
- RRRRWWWWBBBBeeeennnncccchhhh((((3333CCCC++++++++)))) RRRRWWWWBBBBeeeennnncccchhhh((((3333CCCC++++++++))))
-
-
-
- }
-
-
- }
-
-
-
- delete tokener;
- }
- void TestRW::idleLoop(unsigned long n){
- RWCString string(cs); //Subtract out the overhead
- RWCTokenizer *tokener;
- RWCString token, result;
- RWCRegexp re("");
-
-
-
- tokener = new RWCTokenizer(string);
-
-
-
-
- while(n--){
-
-
-
-
- if((token = (*tokener)()).isNull())
- {
- delete tokener;
- tokener = new RWCTokenizer(string);
- token = (*tokener)();
- }
-
-
- re = RWCRegexp(token);
- }
-
-
-
- delete tokener;
- }
-
- PPPPrrrrooooggggrrrraaaammmm oooouuuuttttppppuuuutttt::::
-
- Testing string
-
-
-
- "A multi-character string with lots of words in it to be parsed out and searched for."
- Borland C++ V4.0
- Brute force string search:
-
-
-
- PPPPaaaaggggeeee 4444
-
-
-
-
-
-
- RRRRWWWWBBBBeeeennnncccchhhh((((3333CCCC++++++++)))) RRRRWWWWBBBBeeeennnncccchhhh((((3333CCCC++++++++))))
-
-
-
- Iterations: 35
- Inner loop operations: 1000
- Total operations: 35000
- Elapsed (user) time: 4.596
- Kilo-operations per second: 7.61532
- Borland C++ V4.0
- Rogue Wave search:
- Iterations: 53
- Inner loop operations: 1000
- Total operations: 53000
- Elapsed (user) time: 2.824
-
- PPPPuuuubbbblllliiiicccc CCCCoooonnnnssssttttrrrruuuuccccttttoooorrrrssss
- Kilo-operations per second: 18.7677
-
-
-
- RWBench(double duration = 5, unsigned long ILO=1000,
- const char* machine = 0);
-
-
- The parameter dddduuuurrrraaaattttiiiioooonnnn is the nominal amount of time that the benchmark
- should take in seconds. The virtual function ddddooooLLLLoooooooopppp((((uuuunnnnssssiiiiggggnnnneeeedddd lllloooonnnngggg)))) will
- be called over and over again until at least this amount of time has
- elapsed. The parameter IIIILLLLOOOO is the number of "inner loop operations" that
- should be performed. This parameter will be passed in as parameter NNNN to
- ddddooooLLLLoooooooopppp((((NNNN)))). Parameter mmmmaaaacccchhhhiiiinnnneeee is an optional null terminated string that
- should describe the test environment (perhaps the hardware the benchmark
- is being run on ).
-
- PPPPuuuubbbblllliiiicccc MMMMeeeemmmmbbbbeeeerrrr FFFFuuuunnnnccccttttiiiioooonnnnssss
- virtual void
- ddddooooLLLLoooooooopppp(unsigned long N)=0;
-
-
- A pure virtual function whose actual definition should be supplied by the
- specializing class. This function will be repeatedly called until a time
- duration has elapsed. It should perform the operation to be benchmarked
- NNNN times. See the example.
-
- double
- dddduuuurrrraaaattttiiiioooonnnn() const;
-
-
- Return the current setting for the benchmark test duration. This should
- not be confused with function ttttiiiimmmmeeee(((()))) which returns the actual test time.
-
- virtual void
- ggggoooo();
-
-
- Call this function to run the benchmark.
-
-
-
- PPPPaaaaggggeeee 5555
-
-
-
-
-
-
- RRRRWWWWBBBBeeeennnncccchhhh((((3333CCCC++++++++)))) RRRRWWWWBBBBeeeennnncccchhhh((((3333CCCC++++++++))))
-
-
-
- virtual void
- iiiiddddlllleeeeLLLLoooooooopppp(unsigned long N);
-
-
- This function can help to correct the benchmark for overhead. The
- default definition merely executes a "ffffoooorrrr(((())))" loop NNNN times. See the
- example.
-
- const char *
- mmmmaaaacccchhhhiiiinnnneeee();
-
-
- This function accesses the name of the machine which is passed into the
- benchmark object through ppppaaaarrrrsssseeee(((()))).
-
- virtual void
- ppppaaaarrrrsssseeee(int argc, char* argv[]);
-
-
- This function allows an easy way to change the test duration, number of
- inner loops and machine description from the command line:
-
-
- AAAArrrrgggguuuummmmeeeennnntttt TTTTyyyyppppeeee DDDDeeeessssccccrrrriiiippppttttiiiioooonnnn
-
-
- aaaarrrrggggvvvv[[[[1111]]]] ddddoooouuuubbbblllleeee Duration (sec.)
-
-
- aaaarrrrggggvvvv[[[[2222]]]] uuuunnnnssssiiiiggggnnnneeeedddd lllloooonnnngggg No. of inner loops
-
-
- aaaarrrrggggvvvv[[[[3333]]]] ccccoooonnnnsssstttt cccchhhhaaaarrrr**** Machine
-
-
- void
- ppppaaaarrrrsssseeee(const char *);
-
-
- This is a non-virtual function which provides the same service as
- ppppaaaarrrrsssseeee((((iiiinnnntttt aaaarrrrggggcccc,,,, cccchhhhaaaarrrr **** aaaarrrrggggvvvv[[[[]]]])))), but is designed for Windows users. It
- extracts tokens from the null-terminated command argument provided by
- Windows, then calls the virtual ppppaaaarrrrsssseeee for ANSI C command arguments.
-
- virtual void
- rrrreeeeppppoooorrrrtttt(ostream&) const;
-
-
- Calling this function provides an easy and convenient way of getting an
- overall summary of the results of a benchmark.
-
-
-
-
-
- PPPPaaaaggggeeee 6666
-
-
-
-
-
-
- RRRRWWWWBBBBeeeennnncccchhhh((((3333CCCC++++++++)))) RRRRWWWWBBBBeeeennnncccchhhh((((3333CCCC++++++++))))
-
-
-
- double
- sssseeeettttDDDDuuuurrrraaaattttiiiioooonnnn(double t);
-
-
- Change the test duration to time tttt.
-
- unsigned long
- sssseeeettttIIIInnnnnnnneeeerrrrLLLLooooooooppppssss(unsigned long N);
-
-
- Change the number of "inner loop operations" to NNNN.
-
- virtual void
- wwwwhhhhaaaatttt(ostream&) const;
-
-
- You can supply a specializing version of this virtual function that
- provides some detail of what is being benchmarked. It is called by
- rrrreeeeppppoooorrrrtttt(((()))) when generating a standard report.
-
- void
- wwwwhhhheeeerrrreeee(ostream&) const;
-
-
- This function will print information to the stream about the compiler and
- memory model that the code was compiled under.
-
- unsigned long
- iiiinnnnnnnneeeerrrrLLLLooooooooppppssss() const;
-
-
- Returns the current setting for the number of inner loop operations that
- will be passed into function ddddooooLLLLoooooooopppp((((uuuunnnnssssiiiiggggnnnneeeedddd lllloooonnnngggg NNNN)))) as parameter NNNN.
-
- double
- ttttiiiimmmmeeee() const;
-
-
- Returns the amount of time the benchmark took, corrected for overhead.
-
- unsigned long
- oooouuuutttteeeerrrrLLLLooooooooppppssss() const;
-
-
- Returns the number of times the function ddddooooLLLLoooooooopppp(((()))) was called.
-
- double
- ooooppppssss() const;
-
-
- Returns the total number of inner loop operations that were performed
- (the product of the number of times oooouuuutttteeeerrrrLLLLoooooooopppp(((()))) was called times the
-
-
-
- PPPPaaaaggggeeee 7777
-
-
-
-
-
-
- RRRRWWWWBBBBeeeennnncccchhhh((((3333CCCC++++++++)))) RRRRWWWWBBBBeeeennnncccchhhh((((3333CCCC++++++++))))
-
-
-
- number of inner loop operations performed per call).
-
- double
- ooooppppssssRRRRaaaatttteeee() const;
-
-
- Returns the number of inner loop operations per second.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- PPPPaaaaggggeeee 8888
-
-
-
-